import requests

def get_random_joke():
    url = "https://official-joke-api.appspot.com/random_joke"
    try:
        response = requests.get(url)
        response.raise_for_status() 
        joke_data = response.json()
        setup = joke_data['setup']
        punchline = joke_data['punchline']
        print("这是一个随机笑话:")
        print(f"Q: {setup}")
        input("（按回车键查看答案...）")
        print(f"A: {punchline}")

    except requests.exceptions.RequestException as e:
        print(f"获取笑话失败，错误: {e}")

get_random_joke()